OpenTelemetry Operator概要編
こんにちは、@sugar235711です。
この記事は「ひとりで気になるOSSのソースコード全部読んで何かする Advent Calendar 2025」22日目の記事です。
前回の記事: OpenTelemetry Collector Extension編
OpenTelemetry Operatorは、Kubernetes上でOpenTelemetryの構成要素(Collectorや自動計装ライブラリなど)を管理・制御するためのKubernetes Operatorです。
https://github.com/open-telemetry/opentelemetry-operator?tab=readme-ov-file
3つのCRDが存在します。
OpenTelemetryCollector: OpenTelemetry Collector(後述)をデプロイ・管理するためのカスタムリソースです
Instrumentation: アプリケーションへのOpenTelemetry自動計装(Auto-Instrumentation)の設定を行うカスタムリソースです
OpAMPBridge
参考
https://signoz.io/blog/opentelemetry-operator-complete-guide/
https://speakerdeck.com/k6s4i53rx/getting-started-opentelemetry-operator-on-kubernetes
OpenTelemetryCollectorはそのままspecにCollectorで定義するyamlをかけばk8sのNodeに展開されます。
デプロイモードはDeployment/DaemonSet/StatefulSet/Sidecarで展開できます。
code:yaml
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: example-otelcol
spec:
mode: deployment # Collectorの動作モード(デプロイメント)
config: | # Collectorのコンフィギュレーション(YAML形式)
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
batch: {}
exporters:
logging: {}
service:
pipelines:
traces:
receivers: otlp
processors: batch
exporters: logging
Target Allocator
CollectorでPrometheusメトリクス収集(scrape)をスケールさせる際、各Collectorごとのスクレイプ対象を集中管理して分散割当てする仕組みです。OpenTelemetryCollector CRのspec.targetAllocator.enabled: trueを設定すると、OperatorはTarget Allocator用のDeploymentおよびServiceを追加で生成し、Collectorの設定を書き換えてそのTA経由でスクレイプを行うように自動調整します。たとえば上記StatefulSetモードと組み合わせることで、各CollectorインスタンスがTarget Allocatorから自分の担当するターゲットリストを取得し、重複なく効率的にスクレイプできるようになります。
Instrumentation CRD
Instrumentationリソースは名前空間単位で作成され、OperatorはどのPodに・どの言語用エージェントを・どう設定して注入するかを把握します。
https://opentelemetry.io/docs/platforms/kubernetes/operator/automatic/#:~:text=Configure%20Automatic%20Instrumentation
Podへ計装対象を追加する場合はanottationが必要です(ex. Go: instrumentation.opentelemetry.io/inject-go: "true")
OperatorのAdmission WebhookがそのPod定義をフックし、対応するInstrumentation CRを参照して以下の変更をPodに加えます。
Initコンテナの注入(Goの場合はSidecarコンテナ): 対象言語の計装ライブラリを含むイメージを用いたInit ContainerをPodに追加し、計装エージェントをセットアップします。Go言語のみ例外的に、eBPFベースのエージェントを実行するサイドカーコンテナを注入します。
OpAMPBridge
OpAMPはOpenTelemetry Collector や Agent をリモート管理するためのプロトコルです。
https://speakerdeck.com/k6s4i53rx/getting-started-opentelemetry-collector-with-opamp
https://scrapbox.io/files/69477bdb43529117e253fd6d.png
OpAMPBridge は Kubernetes(CRD / Operator)と OpAMP の橋渡しをするコンポーネントです。実行中に構成を変更するために、Supervisor が OpAMP の実行エージェントとして待機します。
https://scrapbox.io/files/69477be7bb51b218ce451960.png
まとめ
Operatorの概要を見ました。